import 'package:freedom/page/mahjong/common/mahjong_context.dart';
import 'package:freedom/page/mahjong/common/message_content.dart';
import 'package:freedom/page/mahjong/event/disk_direction_update.dart';
import 'package:freedom/page/mahjong/event/user_bump_event.dart';
import 'package:freedom/page/mahjong/message/abstract_action_message.dart';
import 'package:freedom/util/voice_message_sound.dart';

class BumpAction extends AbstractMessageActionHandler<MahjongMessage> {
  @override
  void doMessage(MahjongMessage message) {
    var userDiskInfo = MahjongContext.getUserStateById(message.exeActionUid);
    if (userDiskInfo == null) {
      return;
    }
    /**
     * @type 1 碰牌,2 暗杠, 3 明杠 , 4 点杠
     */
    int cardCode = message.cardCode!;
    // 更改桌面 东南西北
    MahjongContext.postRoomEvent<DiskDirectionUpdate>(DiskDirectionUpdate(
        MahjongContext.getUserStateById(message.exeActionUid)!.direction));
    MahjongContext.postUserEvent<UserBumpEvent>(
        message.exeActionUid, UserBumpEvent(cardCode, message.sourceBySeq));
    MahjongContext().reInitHuCardTips(false);
    MahjongContext.mahjongGameIndex.addBBTH('peng', userDiskInfo.direction);
    // 当下发碰的时候  直接播放声音
    VoiceMessageSound().play("BUMP", close: () {});
    userDiskInfo.export.removeLastCard();
  }
}
